<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Web存储测试</title>
</head>
<body>

<button id="setBtn">存储</button>
<button id="getBtn">获取</button>
<button id="removeBtn">删除</button>
<button id="clearBtn">清空</button>


<script type="text/javascript">

    window.onload = function () {

        document.querySelector("#setBtn").addEventListener("click", function () {

            window.localStorage.setItem("msg", "www.baidu.com");

        }, false);
        document.querySelector("#getBtn").addEventListener("click", function () {
            var msg = window.localStorage.getItem("msg");
            alert(msg);
        }, false);
        document.querySelector("#removeBtn").addEventListener("click", function () {
            window.localStorage.removeItem("msg");
        }, false);
        document.querySelector("#clearBtn").addEventListener("click", function () {
            window.localStorage.clear();
        }, false);


    }


</script>


</body>
</html>